London | 26-ITP-Jan | Boualem Larbi Djebbour | sprint 3 | implement and rewrite tests coursework#1261
Conversation
Implemented the getAngleType function to classify angles and added tests for various angle types, including acute, obtuse, right, straight, reflex, and invalid angles.
…nk is "10" so the string is 3 characters
…e the rank is "10" so the string is 3 characters" This reverts commit 82958b5.
| if (card[0] === "A") return 11; | ||
| if (["J", "Q", "K"].includes(card[0])) return 10; | ||
| if (["2", "3", "4", "5", "6", "7", "8", "9", "10"].includes(card[0])) | ||
| return card[0]; // the parseint() or Number() can be used to convert the string to a number | ||
| throw new Error("invalid rank"); |
There was a problem hiding this comment.
Does your function return the value you expected from each of the following function calls?
getCardValue("+2♠");
getCardValue("2.0♠");
getCardValue("11♠");
getCardValue("2 ♠");
getCardValue("XYZ2♠");
| expect(getAngleType(-1)).toEqual("Invalid angle"); | ||
| expect(getAngleType(0)).toEqual("Invalid angle"); | ||
| expect(getAngleType(360)).toEqual("Invalid angle"); | ||
| expect(getAngleType(361)).toEqual("Invalid angle"); |
There was a problem hiding this comment.
Good job in identifying both boundary cases.
| // case: the absolute value of the numerater is less than the absolute value of the denominater (proper fraction) | ||
| test(`should return true for positive proper fraction`, () => { | ||
| expect(isProperFraction(1, 2)).toEqual(true); | ||
| }); | ||
|
|
||
| // case: the absolute value of the denominater is less than the absolute value of the numerater (improper fraction) | ||
| test(`should return false for positive improper fraction`, () => { | ||
| expect(isProperFraction(2, 1)).toEqual(false); | ||
| }); | ||
|
|
||
| // no need to test the cases where the denominator or numerator or both are negative as I used their absolute value in the function. |
There was a problem hiding this comment.
-
In software industry, the test script we prepared may be used to test future implementation/modification. As a practice, can you also test negative numerator/denominator to make the tests comprehensive?
-
For proper fractions, the condition is, "the absolute value of denominator is larger than the absolute value of the numerator". So we can create a category for proper fractions and describe it as:
should return true when abs(numerator) < abs(denominator)
and then test all combinations of positive/negative numerator and denominator (for proper fraction) in this category.
| test(`Should return 11 when given an ace card`, () => { | ||
| expect(getCardValue("A♠")).toEqual(11); | ||
| }); | ||
| test(`Should return 11 when given an ace card`, () => { | ||
| expect(getCardValue("A♥")).toEqual(11); | ||
| }); | ||
| test(`Should return 11 when given an ace card`, () => { | ||
| expect(getCardValue("A♦")).toEqual(11); | ||
| }); | ||
| test(`Should return 11 when given an ace card`, () => { | ||
| expect(getCardValue("A♣")).toEqual(11); | ||
| }); |
There was a problem hiding this comment.
It's a good idea to test all suit. I think you can combine these tests into a single category.
| test(`Should return 2 when given a 2 card`, () => { | ||
| expect(getCardValue("2♠")).toEqual(2); | ||
| }); | ||
| test(`Should return 3 when given a 3 card`, () => { | ||
| expect(getCardValue("3♥")).toEqual(3); | ||
| }); | ||
| test(`Should return 4 when given a 4 card`, () => { | ||
| expect(getCardValue("4♦")).toEqual(4); | ||
| }); | ||
| test(`Should return 5 when given a 5 card`, () => { | ||
| expect(getCardValue("5♣")).toEqual(5); | ||
| }); | ||
| test(`Should return 6 when given a 6 card`, () => { | ||
| expect(getCardValue("6♥")).toEqual(6); | ||
| }); | ||
| test(`Should return 7 when given a 7 card`, () => { | ||
| expect(getCardValue("7♠")).toEqual(7); | ||
| }); | ||
| test(`Should return 8 when given a 8 card`, () => { | ||
| expect(getCardValue("8♦")).toEqual(8); | ||
| }); | ||
| test(`Should return 9 when given a 9 card`, () => { | ||
| expect(getCardValue("9♠")).toEqual(9); | ||
| }); | ||
| test(`Should return 10 when given a 10 card`, () => { | ||
| expect(getCardValue("10♣")).toEqual(10); | ||
| }); |
There was a problem hiding this comment.
Good idea to test all number cards.
You could also consider combining them into a single category (since they are all number cards), as:
test("should return the value of number cards (2-10)", () => {
expect(getCardValue("2♣︎")).toEqual(2);
...
expect(getCardValue("10♥")).toEqual(10);
// or use a loop to check all values from 2 to 10.
});
And perhaps one category for J, Q, K (face cards) and one category for invalid cases.
| function isProperFraction(numerator, denominator) { | ||
| // TODO: Implement this function | ||
| if (Math.abs(numerator) < Math.abs(denominator)) { | ||
| return true; | ||
| } else { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
There seem to be a syntax error in this function.
Learners, PR Template
Self checklist
Changelist
implement and tests functions
Questions